/**
* 创建者：luyiming
* 该页面用于：
* 创建时间： 2020-03-06 21:47:52
*/
import moment from "moment";
import AbnormalTemplate from "@/template/abnormal.temp.vue";
import Table from "@/components/Table";
import Pagination from "@/components/Pagination"; // 分页
import { getRadPermitOverdue, getNewDeclarePermitInfo, UpdateDeclarePermit } from "@/api/RCIM/RCIM-licence";
import { ExportExcelSupervision } from "@/api/RCIM/RCIM-downloadFile";
export default {
    name: 'RcimLicenceStatistics_view',
    components: {
        AbnormalTemplate,
        Table,
        Pagination
    },
    // 数据
    data() {
        return {
            treeData: {},
			total: 5,
			listLoading: true,
			listQuery: {
				page: 1,
				limit: 10,
				// nodeId: "",
				// startTime: "",
				// endTime: ""
			},
            tableData: [{
                enterprise: '许可证逾期企业',
                legalPerson: '同意'
            }],
			tableHead: [
				{
					id: "enterpriseName",
                    name: "许可证逾期企业",
                    align: "center",
					width: ""
				},
				{
					id: "resolution",
					name: "处理意见",
					align: "center",
					width: ""
				},
				{
					id: "operate",
					name: "操作",
					align: "center",
					width: ""
				}
            ],
            dialogVisible: false,
            licenceInfo: {
                licenceImgUrls: []
            },
			licenceInfoImgs: [],
			resolution: '',
			unTongyi: false,
			canEdit: true,
        }
    },
    // 监听
    watch: {

    },
    // Vue实例初始化完成
    created() {

    },
    // Vue挂载完成
    mounted() {
        // this.getList()
    },
    // Vue实例销毁前
    beforeDestroy(){

    },
    // 挂载的方法
    methods: {
        /**
         * @desc 获取表格数据
         */
        async getList() {
			this.listLoading = true;
			const { data } = await getRadPermitOverdue(this.listQuery);
			this.total = data.total;
			this.tableData = data.data;
			// sessionStorage.setItem(
			// 	"abnormalList",
			// 	JSON.stringify(this.tableData)
			// );
			this.listLoading = false;
        },
        /**
         * @desc 导出为Excel
         */
        downloadExcel(){
			this.$confirm('确认要导出为Excel吗？')
				.then(_ => {
					this.donloadLoading = true;
					this.getExcel({
						callback: ExportExcelSupervision,
						params: this.listQuery,
						id: 'licenceStatics'
					}).then(res => {
						this.donloadLoading = false;
					}).catch(err => {
						this.donloadLoading = false;
					})
				})
				.catch(_ => {});
		},
        /**
         * @desc 表格数据详情
         */
		async handleEdit(row) {
			this.licenceInfoImgs = []
			this.canEdit = row.resolution === '未处理';
			// const {data} = await getLicenceStatisticsImgsList(row.id)
			const { data } = await getNewDeclarePermitInfo(row.id);
			if(!data.data.licenceImgUrls){
				return this.$message.warning('该企业还未上传新许可证')
			}
			this.licenceInfo.licenceImgUrls = [{
				licenceId: '许可证',
				imgUrl: data.data.licenceImgUrls
			}]
			this.licenceInfoImgs = [data.data.licenceImgUrls]
			this.licenceInfo.id = data.data.id;
            // this.licenceInfo = data
            // this.licenceInfoImgs = [require('../../../public/static_img/licence1.jpg'),require('../../../public/static_img/licence2.jpg')]
            // this.licenceInfo.licenceImgUrls[0].imgUrl = require('../../../public/static_img/licence1.jpg')
            // this.licenceInfo.licenceImgUrls[1].imgUrl = require('../../../public/static_img/licence2.jpg')
            this.dialogVisible = true

            // 正式数据下的格式
            //this.licenceInfoImgs = data.licenceImgUrls
            // const tempImgs = []
            // data.licenceImgUrls.forEach((item,index)=> {
                // this.licenceInfo.licenceImgUrls[index] = {}
            //     this.licenceInfo.licenceImgUrls[index].imgUrl = item.url
            // tempImgs.push(item.url)
            // })
            // this.licenceInfoImgs = tempImgs
		},
        /**
         * @desc 左侧点击筛选
		 * @param {Object} param 节点数据
         */
		treeHandle(param) {
            // return
			console.log(param);
			this.listQuery.nodeId = param.id;
			this.listQuery.nodeType = param.type;
			// this.listQuery.startTime = moment(param.startTime).format(
			// 	"YYYY-MM-DD"
			// );
			// this.listQuery.endTime = moment(param.endTime).format("YYYY-MM-DD");
			this.listQuery.treeType = param.treeType;
			this.getList();
        },
        /**
         * @desc 提交表单
		 * @param {String} id 处理id
		 * @param {String} value 值
         */
        async submitSuggest(id,value){
            const params = {
                id,
				suggest: value,
				reason: this.resolution
			}
			if(value === 2){
				this.resolution = '';
				return this.unTongyi = true;
			}
			this.$confirm('是否同意，一旦同意后无法更改')
				.then(_ => {
					UpdateDeclarePermit(params).then(res => {
						if(res.code === 200){
							this.dialogVisible = false;
							this.getList();
							return this.$message.success('处理成功')
						}
						throw new Error('处理失败')
					}).catch( err => {
						this.$message.error(err)
					})
				})
				.catch(_ => {});

		},
        /**
         * @desc 提交表单是否处理
		 * @param {String} id 处理id
         */
		submitSuggestDis(id){
			if(this.resolution === '') {
				return this.$message.warning('请输入理由')
			}
			const params = {
                id,
				suggest: 2,
				reason: this.resolution
			}
			// 调用接口
			UpdateDeclarePermit(params).then(res => {
				if(res.code === 200){
					this.unTongyi = false
					this.dialogVisible = false;
					this.getList();
					return this.$message.success('处理成功')
				}
				throw new Error('处理失败')
			}).catch( err => {
				this.$message.error(err)
			})
		},
		submitSuggesthand(){
			this.unTongyi = false
		}
    },
}
